//
// Created by lingzhitech on 25-10-10.
//
// 13章
#ifndef MESSAGE_HPP
#define MESSAGE_HPP
#include <set>
#include "Folder.hpp"

class Message {
    friend class Folder;
    friend void swap(Message &lhs, Message &rhs);
    friend std::ostream& operator<<(std::ostream& os, const Message& message);
public:
    Message() = default;
    // folders is implicitly initialized to the empty set
    explicit Message(const std::string &str = ""):
    contents(str) { }
    // copy control to manage pointers to this Message
    Message(const Message&); // copy constructor
    Message& operator=(const Message&); // copy assignment
    Message(Message&&);
    Message& operator=(Message&&);
    ~Message(); // destructor
    // add/remove this Message from the specified Folder's set of messages
    void save(Folder&);
    void remove(Folder&);

    void addFolder(Folder*);
    void removeFolder(Folder*);

    void moveFolders(Message*);

private:
    std::string contents; // actual message text
    std::set<Folder*> folders; // Folders that have this Message
    // utility functions used by copy constructor, assignment, and destructor
    // add this Message to the Folders that point to the parameter
    void addMessageToFolders();
    // remove this Message from every Folder in folders
    void removeMessageFromFolders();
};


#endif //MESSAGE_HPP
